﻿// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <string>
#include <memory>
using namespace std;
class StringVector
{
public:
    StringVector(int size = 10)
    {
        strs_ = make_unique<string[]>(size);
        capacity_ = size;
    }
    void Push(const string& s)
    {
        if (size_ < capacity_)
        {
            strs_[size_] = s;
            size_++;
        }
        else
        {
            cout << "capacity_ *= 2;\n";
            capacity_ *= 2;
            auto strs = make_unique<string[]>(capacity_);
            for (int i =0;i < size_; i++)
            {
                strs[i] = move(strs_[i]);
            }
            strs_ = move(strs);
            strs_[size_] = s;
            size_++;
        }
    }
    int Size() { return size_; }
    const string &operator[](int index) 
    {
        return strs_[index];
    }
private:
    unique_ptr<string[]> strs_;
    int size_{0};
    int capacity_{ 0 };
};
int main()
{
    StringVector vec(2);
    vec.Push("test 001");
    vec.Push("test 002");
    vec.Push("test 003");
    for (int i = 0; i < vec.Size(); i++)
    {
        cout << vec[i] << endl;
    }
}